package com.fanshuai.springcloud.config;

import com.fanshuai.springcloud.handler.HelloHandler;
import com.fanshuai.springcloud.service.UserService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import javax.annotation.Resource;

@Configuration
public class MainConfig {
    @Resource
    private HelloHandler helloHandler;

    @Bean(name = "baseUserService")
    @ConditionalOnMissingBean(UserService.class)
    public UserService userService() {
        return new UserService();
    }

    @Bean
    public RouterFunction<ServerResponse> helloRouter() {
        return RouterFunctions.route(RequestPredicates.GET("hello"), helloHandler::hello1)
                .andRoute(RequestPredicates.GET("hello2"), helloHandler::hello2);
    }
}
